package logic

import (
	"beike/cache"
	"beike/pkg"
	"context"
	"time"

	"beike/houserpc/houserpc"
	"beike/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SetCacheLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSetCacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetCacheLogic {
	return &SetCacheLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SetCacheLogic) SetCache(in *houserpc.SetCacheRequest) (*houserpc.SetCacheResponse, error) {
	// todo: add your logic here and delete this line

	ip := pkg.GetOutboundIP()

	cache.Rdb.Set(l.ctx, "token"+ip, in.Token, time.Hour*1)

	return &houserpc.SetCacheResponse{}, nil
}
